package com.zzedu.web.controller.monitor;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zzedu.common.annotation.Log;
import com.zzedu.common.core.controller.BaseController;
import com.zzedu.common.core.domain.AjaxResult;
import com.zzedu.common.core.page.TableDataInfo;
import com.zzedu.common.enums.BusinessType;
import com.zzedu.common.utils.poi.ExcelUtil;
import com.zzedu.system.domain.SysOperationLog;
import com.zzedu.system.service.ISysOperationLogService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 操作日志记录
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperationLogController extends BaseController {
    @Autowired
    private ISysOperationLogService sysOperationLogService;

    @PreAuthorize("@permission.hasAnyPermissions('monitor:operlog:list')")
    @RequestMapping("/list")
    public TableDataInfo list(@RequestBody SysOperationLog sysOperationLog) {
        IPage<SysOperationLog> list = sysOperationLogService.selectOperLogList(sysOperationLog.getPageDTO(), sysOperationLog);
        return getDataTable(list);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@permission.hasAnyPermissions('monitor:operlog:export')")
    @RequestMapping("/export")
    public void export(HttpServletResponse response, SysOperationLog sysOperationLog) {
        IPage<SysOperationLog> list = sysOperationLogService.selectOperLogList(new Page(1L, -1L), sysOperationLog);
        ExcelUtil<SysOperationLog> util = new ExcelUtil<SysOperationLog>(SysOperationLog.class);
        util.exportExcel(response, list.getRecords(), "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@permission.hasAnyPermissions('monitor:operlog:remove')")
    @RequestMapping("/clean")
    public AjaxResult clean() {
        sysOperationLogService.cleanOperLog();
        return success();
    }
}
